<template>
  <div class="edit credit" >
    <Form ref="product" :model="product" :rules="ruleValidate" :label-width="150">
      <h3 class="title">审核流程</h3>
      <FormItem label="人工审核状态" prop="status1">
        <RadioGroup v-model="product.status1">
          <Radio label="1">开</Radio>
          <Radio label="0">关</Radio>
        </RadioGroup>
      </FormItem>
      <h3 class="title">放款流程</h3>
      <FormItem label="财务电核状态" prop="status2">
       <RadioGroup v-model="product.status2">
          <Radio label="1">开</Radio>
          <Radio label="0">关</Radio>
        </RadioGroup>
      </FormItem>

      <FormItem label="	手动放款状态" prop="status3">
       <RadioGroup v-model="product.status3">
         <Radio label="1">开</Radio>
         <Radio label="0">关</Radio>
       </RadioGroup>
      </FormItem>
      <FormItem >
        <Button @click="cancel" style="margin-right:5px">取消</Button>
        <Button type="primary" @click="ok1">确定</Button>
      </FormItem>
    </Form>
  </div>
</template>

<script>
export default {
  props:['nameSelect'],
  data() {
    return {
      tag: {
        title: "流程配置",
        path: "/work/flowConfig/edit"
      },
      type:1,
      typeList: [],
      statusList:[//0未发布1发布2下架
       /* {
          id:0,
          name:'未发布 '
        },*/
        {
          id:1,
          name:'上架 '
        },
        {
          id:2,
          name:'下架 '
        }
        ],
      product: {
        status1:'0',
        status2:'0',
        status3:'0',
      },
      ruleValidate: {
        status1: [{ required: true, message: "请选择状态", trigger: "blur" , }],
        status2: [{ required: true, message: "请选择状态", trigger: "blur" , }],
        status3: [{ required: true, message: "请选择状态", trigger: "blur" , }],

      }
    };
  },
  mounted() {
    this.getConfig();
    // let tagList = JSON.parse(sessionStorage.getItem('tag'));
    // let status = true;
    // let name = '';
    // tagList.map((item,index) => {
    //   if(item.title == this.tag.title){
    //     status = false;
    //     name = item.name;
    //     return false;
    //   }
    // })
    // if(status){
    //   this.tag.name = this.nameSelect;
    // }else{
    //   this.tag.name = name;
    // }
    this.tag.name = this.nameSelect;
    this.$store.commit('changeTag', this.tag.path);
    this.$store.commit('openPage', this.tag);

  },
  methods: {
    resetValidate(name) {
      //清空判断
      this.$refs[name].resetFields();
    },
    getConfig(){
      this.$post('/sysDict/switch/list').then(res => {
      console.log(res.data,'res1');
      res.data.map((item,index) => {
        switch(item.key){
          case 'order_loan_open' :
            this.product.key1 = item.key;
            this.product.status1 = item.status;
            this.product.groupCode1 = item.groupCode;
            break;
          case 'financial_audit_open' :
            this.product.key2 = item.key;
            this.product.status2 = item.status;
            this.product.groupCode2 = item.groupCode;
            break;
          case 'financial_loan_open' :
            this.product.key3 = item.key;
            this.product.status3 = item.status;
            this.product.groupCode3 = item.groupCode;
            break;
        }

      })
    })
    },
    ok() {
      //确定
      let url = "";
      this.$refs["product"].validate(valid => {
        if (valid) {
          let data = {
            id:this.product.id,
            name:this.product.name,
            money:this.product.money,
            realMoney:this.product.realMoney,
            day:this.product.day,
            dayRate:this.product.dayRate,
            repayInterest:this.product.repayInterest,
            serviceCharge:this.product.serviceCharge,
            totalCost:this.product.totalCost,
            poundageRate:this.product.poundageRate,
            overdueDayRate:this.product.overdueDayRate,
            penaltyDayRate:this.product.penaltyDayRate,
            // merchantId:this.product.merchantId,
            status: this.product.status
          };
          if (this.$route.query.title == "新增产品") {
            url = "/bkproduct/append";
          } else if (this.$route.query.title == "编辑产品") {
            url = "/bkproduct/modify";
          }
          this.$post(url, data).then(
            res => {
              if (res.code === 0) {
                console.log(res, "edit");
                this.$Message.primary(`${this.$route.query.title}成功！`);
                this.$router.push({path:'/work/credit/list'})
              }
            },
            err => {
              console.log(err);
            }
          );
        }
      });
    },
    ok1(){
      this.$Modal.confirm({
        title: '请确认一下信息',
        content: `<div>
          <p><span style="color:#333;font-weight:600">审核配置 ：</span>&nbsp;&nbsp;&nbsp;人工审核状态：${this.product.status1 == 0 ?'关闭' : '打开'} </p>
          <p style="float:left;color:#333;font-weight:600">放款配置 ：</p>
          <p style="float:left">&nbsp;&nbsp;&nbsp;财务电核状态：${this.product.status2 == 0 ?'关闭' : '打开'} <br/>&nbsp;&nbsp;&nbsp;手工放款状态：${this.product.status3 == 0 ?'关闭' : '打开'}</p>
        </div>
        <div style="clear:both"> </div>
        `,
        onOk: () => {
          // let dataobj  = {
          //  "paramList":  {
          //      key : this.product.key1,
          //      status :this.product.status1 ,
          //      groupCode : this.product.groupCode1
          //   },
          //   {
          //      key : this.product.key2,
          //      status : this.product.status2,
          //      groupCode : this.product.groupCode2
          //   },
          //   {
          //      key : this.product.key3,
          //      status : this.product.status3,
          //      groupCode : this.product.groupCode3
          //   }

          // }
    let obj1 = {
      key : this.product.key1,
      status : this.product.status1,
      groupCode : this.product.groupCode1
    };
    let obj2 = {
      key : this.product.key2,
      status : this.product.status2,
      groupCode : this.product.groupCode2
    };
    let obj3 = {
      key : this.product.key3,
      status : this.product.status3,
      groupCode : this.product.groupCode3
    };

  // var objData ={
  //   obj1:obj1,
  //   obj2:obj2,
  //   obj3:obj3,
  // }

  var objData =[
    {
      key : this.product.key1,
      status : this.product.status1,
      groupCode : this.product.groupCode1
    },
    {
      key : this.product.key2,
      status : this.product.status2,
      groupCode : this.product.groupCode2
    },
    {
      key : this.product.key3,
      status : this.product.status3,
      groupCode : this.product.groupCode3
    },
  ]

          this.$post('/sysDict/switch',
           {paramList:JSON.stringify(objData)}).then(res => {
             if(res.code == 0){
              this.$Message.success('配置成功');
              this.getConfig();
             }else{
               this.$Message.error('配置失败');
              this.getConfig();
             }
            console.log(res,'result');
          })
        },
        onCancel: () => {
        }
      });
    },
    cancel() {
      // this.$router.push({path:'/work/credit/list'})
      this.resetValidate("product");
      this.getConfig();
    }
  }
};
</script>

<style scoped lang="less">
.edit {
  width: 50%;
  margin-left:50px;
  // background:#fff;
  // margin:0 auto;
  // padding: 50px 10px 150px;

}
.ivu-input-group .ivu-input {
  text-align: center;
}
.ivu-input-group-prepend,
.ivu-input-group-append {
  width: 36px !important;
}
.credit {
  h3 {
    margin-bottom: 15px;
    margin-left: 10px;
    border-left: solid 3px #20a0ff;
    padding-left: 15px;
    font-weight: bolder;
    font-size: 16px;
    color: #000;
  }
}
// /deep/ .ivu-modal-confirm-footer {
//     clear: both;
// }
</style>
